package com.scc.controller;

import com.scc.pojo.Message;
import com.scc.pojo.MessageList;
import com.scc.pojo.Result;
import com.scc.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/message")
public class MessageController {
    //server层
    @Autowired
    private MessageService messageService;

    ///添加消息列表
    @PostMapping("/list")
    public Result addMessageList(@RequestBody MessageList messageList) {
        log.info("添加聊天消息列表信息:{}", messageList);
        messageService.insertMessageList(messageList);
        return Result.success();
    }

    ///获取消息列表
    @GetMapping("/list")
    public Result getMessageList(Integer fromEmpId) {
        log.info("获取消息聊天列表的员工id:{}", fromEmpId);
        //返回一个消息列表集合
        List<MessageList> messageLists = messageService.getMessageList(fromEmpId);
        return Result.success(messageLists);
    }

    ///获取历史聊天记录
    @GetMapping("/{id}")
    public Result getHistoryMessage(@PathVariable Integer id) {
        log.info("获取历史聊天记录id:{}", id);
        //返回一个消息对象的集合
        List<Message> messages = messageService.getHistoryMessage(id);
        return Result.success(messages);
    }

    ///清空聊天记录
    @DeleteMapping("/{id}")
    public Result deleteMessageList(@PathVariable Integer id) {
        log.info("删除聊天记录对应的id:{}",id);
        messageService.deleteMessageList(id);
        return Result.success();
    }
}
